/**                   GNU GENERAL PUBLIC LICENSE
 *                       Version 3, 29 June 2007
 *
 * Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
 * Everyone is permitted to copy and distribute verbatim copies
 * of this license document, but changing it is not allowed.
 * See License.txt file that comes with this distribution
 *
 *
 * Author: Vitaly German <vitaly.german@gmail.com>, (C) 2007-2008
 * 
 **/
#pragma once

///////////////////////////////////////////////////////
/// 1. Inequalities related:
/// x > y  -> y < x
/// x >= y -> y <= x
///////////////////////////////////////////////////////

struct equs_transform
{
  template <class Node,class Iter>
  void operator () (Node &node, Iter,Iter)const
  {
    typedef typename Node::parse_node_t pn_t; // actual value type
    assert(node.children.size()==2);
    std::string node_mark(node.value.begin(),node.value.end());
    
    boost::spirit::parser_id id = node.value.id();

    bool root = node.value.is_root();
    std::string mk;

    if (node_mark == "<")
    {
      mk = ">";
    }
    else if (node_mark == "<=")
    {
      mk = ">=";
    } else
    	return;

    node.value = pn_t(mk.begin(), mk.end());
    std::swap(node.children[0],node.children[1]);
    node.value.id(id); 
    node.value.is_root(root);
  };
  
};

struct ToLower {
  template <class T>
  T operator()(T ch){
     return std::tolower(ch);
  }
};

struct logic_transform
{
  template <class Node,class Iter>
  void operator () (Node &node, Iter,Iter)const
  {
	typedef typename Node::parse_node_t pn_t; // actual value type
    
	
    std::string node_mark(node.value.begin(),node.value.end());
   // std::transform(node.value.begin(),node.value.end(), node.value.begin(), ToLower()); 
    
	boost::spirit::parser_id id = node.value.id();

    bool root = node.value.is_root();
    std::string mk;

    if ((node_mark == "|/") || (node_mark == "||") ||(node_mark == "\\|")||(node_mark == "\\/") || (node_mark == "or"))
    {
      mk = "|";
    }
    else if ((node_mark == "and") || (node_mark == "&&") || (node_mark == "/\\"))
    {
      mk = "&";
	} else if ((node_mark == "Exist") || (node_mark == "Exists")) {
      mk = "Exists";
	} else
    	return;

    node.value = pn_t(mk.begin(), mk.end());
    node.value.id(id); 
    node.value.is_root(root);
  }
};


